<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="java.io.FileNotFoundException" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.InputStream" %>
<%
	String fileName = (String)request.getParameter("name");
	String filePath = (String)request.getParameter("path");
	String path = filePath + fileName;
	InputStream is = null;
	
	if(fileName != null && filePath != null && !fileName.equals("null") && !filePath.equals("null")){
	
		fileName = new String(fileName.getBytes("ISO-8859-1"),"UTF-8");
		filePath = new String(filePath.getBytes("ISO-8859-1"),"UTF-8");
		response.setContentType("application/octet-stream");
		response.addHeader("Content-Disposition","attachment;filename=" + fileName + "");
		
		byte[] b = new byte[1024]; 
		int size = 0; 
		try {
		  is = new FileInputStream(path);
		  while((size=is.read(b))>0){
		  	response.getOutputStream().write(b,0,size);
		  }
		 response.flushBuffer();
	  } catch (FileNotFoundException e) {
		    e.printStackTrace();
			System.out.print("<table id='1' width='100%' align='center'><tr height='30'><td align='center'>文件不存在1！</td></tr></table>");
		} catch (IOException e) {
	        e.printStackTrace();
			System.out.print("<table id='2' width='100%' align='center'><tr height='30'><td align='center'>文件不存在2！</td></tr></table>");
		} catch (Exception e) {
	        e.printStackTrace();
			System.out.print("<table id='3' width='100%' align='center'><tr height='30'><td align='center'>文件不存在3！</td></tr></table>");
		} finally {
			if(is != null){
				is.close();
				is = null;
			}
		}
  }else{
  	System.out.print("<table id='4' width='100%' align='center'><tr height='30'><td align='center'>文件不存在4！</td></tr></table>");
  }
%>